#include "serialThread.h"
#include <QDebug>



SerialThread::SerialThread(QString portName,BaudRateType baud, DataBitsType databits, ParityType parity, StopBitsType stopbits, FlowType flow, long timeout)
{
    struct PortSettings ttySetting; // s3c2440--{BAUD115200,DATA_8,PAR_NONE,STOP_1,FLOW_OFF,500};
    myCom = new Posix_QextSerialPort(portName,ttySetting,QextSerialBase::Polling);
    myCom->open(QIODevice::ReadWrite);    //以可读写方式打开串口
    myCom->setBaudRate(baud);
    myCom->setDataBits(databits);
    myCom->setParity(parity);
    myCom->setStopBits(stopbits);
    myCom->setFlowControl(flow);
    myCom->setTimeout(timeout);
    qDebug("%d",timeout);
}

void SerialThread::run()
{
    while(1){
       usleep(5000);    //delay 5ms
       QByteArray temp = myCom->readAll();          //读取串口缓冲区的所有数据给临时变量temp
       emit this->serialFinished(temp);
    }
}
